package com.proposition.paper.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.proposition.commons.model.StrategyOne;
import com.proposition.commons.model.StrategyTwo;
import com.proposition.paper.mapper.PaperStrategyOneMapper;
import com.proposition.paper.mapper.PaperStrategyTwoMapper;
import com.proposition.paper.service.PaperStrategyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 试卷组卷策略实现类
 *
 * @author 杨凯
 * @create 2017-12-25 9:25
 **/
@Service
public class PaperStrategyServiceImpl implements PaperStrategyService {

	@Autowired
	private PaperStrategyOneMapper oneMapper;
	@Autowired
	private PaperStrategyTwoMapper twoMapper;

	@Transactional(rollbackFor = Exception.class)
	@Override
	public void insertStrategy(StrategyOne one, StrategyTwo two) {
		oneMapper.insert(one);
		twoMapper.insert(two);
	}

	@Override
	public StrategyOne getStrategyOne() {
		Wrapper<StrategyOne> wrapper = new EntityWrapper<StrategyOne>().orderBy("created",false);
		return oneMapper.selectList(wrapper).get(0);
	}

	@Override
	public StrategyTwo getStrategyTwo() {
		Wrapper<StrategyTwo> wrapper = new EntityWrapper<StrategyTwo>().orderBy("created",false);
		return twoMapper.selectList(wrapper).get(0);
	}
}
